import { reactive } from 'vue'
import { IRole } from '../role/useRoleModel'

export interface IAdmin {
    type?: string,
    id: string | number,
    username: string,
    password: string,
    name: string,
    tel: string,
    email: string,
    is_active: boolean,
    date_lock: string,
    role: string | number
    department: string | number
}

export interface IAdminInfo {
    username: string,
    password?: string,
    name: string,
    tel: string,
    email: string,
    is_active: boolean,
    date_lock: string,
    role: string | number
    department: string | number
}

export interface IChoice {
    deptList: [],
    roleList: Array<IRole>
}

export default function useAdminModel() {
    // 初始化数据
    const iAdminModel = (): IAdmin => {
        return {
            type: '',
            id: 0,
            username: '',
            password: '',
            name: '',
            tel: '',
            email: '',
            is_active: false,
            date_lock: '',
            role: '',
            department: ''
        }
    }

    // 管理员验证规则
    const adminRules = reactive({
        department: [{
            required: true,
            message: '请选择部门!',
            trigger: 'blur',
        }],
        username: [{
            required: true,
            message: '请填写账号!',
            trigger: 'blur',
        }, {
            max: 32,
            message: '最大长度32位!',
            trigger: 'blur'
        }],
        name: [{
            max: 32,
            message: '最大长度32位!',
            trigger: 'blur'
        }],
        tel: [{
            max: 15,
            message: '最大长度15位!',
            trigger: 'blur'
        }],
        email: [{
            pattern: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
            message: '请填写正确邮箱格式!',
            trigger: 'blur',
        }],
        role: [{
            required: true,
            message: '请选择角色!',
            trigger: 'blur',
        }],
        date_lock: [{
            required: true,
            message: '请选择时间!',
            trigger: 'blur',
        }]
    })


    return { iAdminModel, adminRules }
}
